package jp.co.sharp.android.parents.kidsguard.common;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import jp.co.sharp.android.parents.kidsguard.R;

public class StatueSelectDlg extends Dialog {

    private OnCameraSetListener mOnCameraSetListener;
    private OnAlbumSetListener mOnAlbumSetListener;
    private StatueSelectDlg mStatueSelectDlg;

    public StatueSelectDlg(@NonNull Context context) {
        super(context);
        this.mStatueSelectDlg = this;
    }

    public StatueSelectDlg(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.mStatueSelectDlg = this;
    }

    protected StatueSelectDlg(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.mStatueSelectDlg = this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dlg_statue_select);

        initDlg();
    }

    private void initDlg() {

        TextView dlgCameraBtn = (TextView)findViewById(R.id.dlgCameraBtn);
        dlgCameraBtn.setOnClickListener(new ListenerCameraBtn());
        TextView dlgAlbumBtn = (TextView)findViewById(R.id.dlgAlbumBtn);
        dlgAlbumBtn.setOnClickListener(new ListenerAlbumBtn());
        Button dlgCancelBtn = (Button)findViewById(R.id.dlgCancelBtn);
        dlgCancelBtn.setOnClickListener(new ListenerCancel());
    }

    /**
     * カメラで撮影
     */
    public interface OnCameraSetListener {
        void onOperateSet();
    }

    /**
     * 端末内の画像から選択
     */
    public interface OnAlbumSetListener {
        void onOperateSet();
    }

    /*
     * 对外公开方法让Activity实现
     */
    public void setOnCameraSetListener(OnCameraSetListener callBack) {
        mOnCameraSetListener = callBack;
    }

    /*
     * 对外公开方法让Activity实现
     */
    public void setOnAlbumSetListener(OnAlbumSetListener callBack) {
        mOnAlbumSetListener = callBack;
    }

    class ListenerCameraBtn implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            if (mOnCameraSetListener != null) {
                mOnCameraSetListener.onOperateSet();
            }
        }
    }

    class ListenerAlbumBtn implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            if (mOnAlbumSetListener != null) {
                mOnAlbumSetListener.onOperateSet();
            }
        }
    }

    class ListenerCancel implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            mStatueSelectDlg.dismiss();
        }
    }
}
